import React,{ Component }from 'react'
import Play from "./play"
import Top from "./top"
import Geci from "./geci"
import Img from "./img"
import {withRouter} from 'react-router-dom'
import {user} from "../../api/api"
class Bf extends Component{
	constructor(){
		super()
		this.state={
			data:'',
			time:[],
			size:'',
			flag:true,
			show:'',
			id:'',
			arr:"",
			newId:''
		}
	}

	btn1(){
		this.props.history.go(-1)
	}
	componentWillMount(){
		let ids=this.props.location.search.split('?')
		let id1=ids[1].split('&')
		let id2=id1[0].split('=')
		let id3
		if(id1[1]){
			id3=id1[1].split('=')
		}
		// 924680166
		let obj=[]
		if(typeof parseInt(id2[1]) == 'number'){
			user(id3[1]).then((res)=>{
				if(res){
					res.data.privileges.forEach((item)=>{
						obj.push(item.id)
					})
					this.setState({
						arr:obj,
						
					})
				}
			})
			this.newid(id2[1])
		}else{
			this.newid(id2[1][0])
			id2[1].split(0,1)
			this.setState({
				arr:id2[1]				
			})
		}
	}
	btn(e){
		this.setState({
			flag:!this.state.flag
		})
	}
	newid(e){
		this.setState({
			id:e
		})
	}
	render(){
		return (
			<div className='father'>
				<Top num={this.state.id} fh={this.btn1.bind(this)}/>
				<div onClick={this.btn.bind(this)} >
					<Img show={this.state.flag} num={this.state.id}/>
					<Geci num={this.state.id} />
				</div>
				<Play nums={this.state.id} arr={this.state.arr} jieshou={this.newid.bind(this)}/>
			</div>
		)
	}
}
export default withRouter(Bf)